package com.acxy.cms;

import com.acxy.ants.common.kit.PropKit;
import com.acxy.ants.common.kit.StrKit;
import com.acxy.ants.core.plugin.db.Db;
import com.acxy.ants.core.plugin.db.DruidPlugin;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author MrShun
 * @version 1.0
 * @Date 2017-06-17
 */
public class CreateData implements Runnable{

    static int count = 0;

    private String name = null;

    public CreateData(String name){
        this.name = name;
    }

    public static void main(String[] args) throws SQLException {
        for (int i= 0; i< 200;i++) {
            Thread thread = new Thread(new CreateData("~ 当前第 "+ i +" 条线程在执行"));
            thread.start();
        }
    }

    @Override
    public void run() {
        PropKit.use("resources.properties");
        DruidPlugin druidPlugin = new DruidPlugin(PropKit.getStr("url"), PropKit.getStr("driverClassName"), PropKit.getStr("username"), PropKit.getStr("password"));
        druidPlugin.start();

        Db db = new Db(druidPlugin.getDataSource());
        List cs = db.list("SELECT distinct(column_name) FROM information_schema.columns WHERE table_name=? and table_schema = ?", "sys_user", "ants-cms");
        StringBuffer sb = new StringBuffer();
        StringBuffer sb1 = new StringBuffer();
        int i=0;
        for(Object obj: cs){
            Object c = ((Map)obj).get("column_name");
            if(!"id".equals(c)) {
                sb.append(c);
                sb1.append("?");
            }
            if(cs.size()-1!=i && !"id".equals(c)){
                sb.append(",");
                sb1.append(",");
            }
            System.out.println(c);
            i++;
        }
        String sql = "insert into sys_user("+sb.toString()+") values("+sb1.toString()+")";
        System.out.println(sql);
        System.out.println(cs.size());

        while (true){
            db.insert(sql,  RandomValue.getEmail(1, 5), "i/sV2VpTPy7Y+ppesmkCmM==", 1, RandomValue.getChineseName(), "pinyin", 1
                    , "upload/tx.png", RandomValue.getTel(), RandomValue.getEmail(1, 8), "lisbank", "ewobbak", "321312", "openid"
                    , "运维工程师",2, "222.112.84.120", new Date(), 0, "s", new Date(), "cess", new Date(), "cess", 0);
            count++;
            System.out.println(name + " " + CreateData.count);
            if (count == 100000) System.exit(0);
        }
    }
}
